﻿using Newtonsoft.Json;
using System.Drawing;

namespace Platform.Core.Models
{
    [JsonObject]
    public class Watermark
    {
        [JsonProperty("canvasWidth")]
        public int CanvasWidth { get; set; }
        [JsonProperty("canvasHeight")]
        public int CanvasHeight { get; set; }

        [JsonProperty("width")]
        public int Width { get; set; }

        [JsonProperty("height")]
        public int Height { get; set; }

        [JsonProperty("x")]
        public float X { get; set; }

        [JsonProperty("y")]
        public float Y { get; set; }

        [JsonProperty("fontSize")]
        public float FontSize { get; set; }

        [JsonProperty("fontFamily")]
        public string FontFamily { get; set; }

        [JsonProperty("fontStyle")]
        public FontStyle FontStyle { get; set; }

        [JsonIgnore]
        public Font Font
        {
            get
            {
                if (string.IsNullOrEmpty(FontFamily))
                {
                    FontFamily = "Microsoft YaHei";
                }
                var font = new Font(FontFamily, FontSize, FontStyle, GraphicsUnit.Pixel);

                return font;
            }
        }

        [JsonProperty("fontColor")]
        public string FontColorValue { get; set; }

        [JsonIgnore]
        public virtual Color FontColor
        {
            get
            {
                if (string.IsNullOrEmpty(FontColorValue))
                {
                    return Color.Black;
                }
                return ColorTranslator.FromHtml(FontColorValue);
            }
        }

        [JsonProperty("text")]
        public string Text { get; set; }

        [JsonProperty("textX")]
        public float TextX { get; set; }
        [JsonProperty("textY")]
        public float TextY { get; set; }

        [JsonProperty("textHeight")]
        public float TextHeight { get; set; }
        [JsonProperty("textWidth")]
        public float TextWidth { get; set; }

        [JsonIgnore]
        public RectangleF TextRectangle
        {
            get
            {
                var location = new PointF(TextX, TextY);
                var size = new SizeF(TextWidth, TextHeight);//默认 w: 200, h:30
                var textRectangle = new RectangleF(location, size);

                return textRectangle;
            }
        }

        [JsonProperty("rotateAngle")]
        public float RotateAngle { get; set; }

        [JsonProperty("rotateX")]
        public float RotateX { get; set; }

        [JsonProperty("rotateY")]
        public float RotateY { get; set; }

        [JsonIgnore]
        public PointF RotatePoint
        {
            get
            {
                var location = new PointF(RotateX, RotateY);
                return location;
            }
        }

    }
}
